home *** CD-ROM | disk | FTP | other *** search
/ Aminet 30 / Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso / Aminet / dev / lang / SmallEiffel.lha / SmallEiffel / lib_se / when_item_2.e < prev    next >
Text File  |  1998-12-22  |  4KB  |  135 lines

  1. --          This file is part of SmallEiffel The GNU Eiffel Compiler.
  2. --          Copyright (C) 1994-98 LORIA - UHP - CRIN - INRIA - FRANCE
  3. --            Dominique COLNET and Suzanne COLLIN - colnet@loria.fr 
  4. --                       http://www.loria.fr/SmallEiffel
  5. -- SmallEiffel is  free  software;  you can  redistribute it and/or modify it 
  6. -- under the terms of the GNU General Public License as published by the Free
  7. -- Software  Foundation;  either  version  2, or (at your option)  any  later 
  8. -- version. SmallEiffel is distributed in the hope that it will be useful,but
  9. -- WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  10. -- or  FITNESS FOR A PARTICULAR PURPOSE.   See the GNU General Public License 
  11. -- for  more  details.  You  should  have  received a copy of the GNU General 
  12. -- Public  License  along  with  SmallEiffel;  see the file COPYING.  If not,
  13. -- write to the  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  14. -- Boston, MA 02111-1307, USA.
  15. --
  16. class WHEN_ITEM_2
  17. --
  18. -- To store a slice value of a when clause in an inspect instruction.
  19. --
  20. -- Exemple :
  21. --          inspect ...
  22. --              when foo .. bar, then ...
  23. -- 
  24.  
  25. inherit WHEN_ITEM; 
  26.          
  27. creation {E_WHEN,WHEN_ITEM_2}
  28.    make
  29.    
  30. feature {ANY}
  31.    
  32.    lower, upper: EXPRESSION;
  33.    
  34.    lower_value, upper_value: INTEGER;
  35.    
  36. feature {NONE}
  37.    
  38.    make(l, u: EXPRESSION) is
  39.       require
  40.      l /= Void;
  41.      u /= Void
  42.       do
  43.      lower := l;
  44.      upper := u;
  45.       ensure
  46.      lower = l;
  47.      upper = u
  48.       end;
  49.    
  50. feature {ANY}
  51.    
  52.    start_position: POSITION is
  53.       do
  54.      Result := lower.start_position;
  55.       end;
  56.    
  57. feature {E_WHEN,WHEN_ITEM_2}
  58.    
  59.    to_runnable_integer(ew: like e_when): like Current is
  60.       local
  61.      ct: TYPE;
  62.      v: like lower;
  63.       do
  64.      if e_when = Void then
  65.         e_when := ew;
  66.         ct := small_eiffel.top_rf.current_type;
  67.         v := lower.to_runnable(ct);
  68.         if v /= Void and then v.result_type.is_integer then
  69.            lower := v; 
  70.            lower_value := lower.to_integer;
  71.         else        
  72.            error(lower.start_position,fz_biv);
  73.         end;
  74.         v := upper.to_runnable(ct);
  75.         if v /= Void and then v.result_type.is_integer then
  76.            upper := v; 
  77.            upper_value := upper.to_integer;
  78.         else        
  79.            error(upper.start_position,fz_biv);
  80.         end;
  81.         e_when.add_when_item_2(Current);
  82.         Result := Current;
  83.      else
  84.         !!Result.make(lower,upper);
  85.         Result := Result.to_runnable_integer(ew);
  86.      end;
  87.       end;
  88.    
  89.    to_runnable_character(ew: like e_when): like Current is
  90.       local
  91.      ct: TYPE;
  92.      v: like lower;
  93.       do
  94.      if e_when = Void then
  95.         e_when := ew;
  96.         ct := small_eiffel.top_rf.current_type;
  97.         v := lower.to_runnable(ct);
  98.         if v /= Void and then v.result_type.is_character then
  99.            lower := v; 
  100.            lower_value := lower.to_integer;
  101.         else        
  102.            error(lower.start_position,fz_bcv);
  103.         end;
  104.         v := upper.to_runnable(ct);
  105.         if v /= Void and then v.result_type.is_character then
  106.            upper := v; 
  107.            upper_value := upper.to_integer;
  108.         else        
  109.            error(upper.start_position,fz_bcv);
  110.         end;
  111.         e_when.add_when_item_2(Current);
  112.         Result := Current;
  113.      else
  114.         !!Result.make(lower,upper);
  115.         Result := Result.to_runnable_character(ew);
  116.      end;
  117.       end;
  118.    
  119.    pretty_print is
  120.       do
  121.      lower.pretty_print;
  122.      fmt.put_string("..");
  123.      upper.pretty_print;
  124.       end;
  125.  
  126. feature {E_WHEN}
  127.  
  128.    eval(exp: INTEGER): BOOLEAN is
  129.       do
  130.      Result := (lower_value <= exp) and (exp <= upper_value);
  131.       end;
  132.  
  133. end -- WHEN_ITEM_2
  134.  
  135.